package com.lvyq.myplayer.model.singer

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.lvyq.myplayer.model.index.IndexHotSongBean
import com.lvyq.myplayer.net.api.singerApiService
import kotlinx.coroutines.launch

/**
 * 文件描述：SingerAlbumModel 歌手专辑
 * 作者：lvyq
 * 创建时间：2025-04-08
 * 修改时间：2025-04-08
 */
class SingerAlbumModel : ViewModel() {
    // 初始化数据（带标记）
    private val _initialData = MutableLiveData<SingerAlbumBean>()
    val initialData: LiveData<SingerAlbumBean> = _initialData

    // 加载更多数据（带标记）
    private val _loadMoreData = MutableLiveData<SingerAlbumBean>()
    val loadMoreData: LiveData<SingerAlbumBean> = _loadMoreData

    fun albumPage( id:Int,offset: Int,pageSize:Int){
        var pageNum: Int = (offset - 1) / pageSize
        pageNum=pageNum + 1
        //接口从1开始，这里加1
        viewModelScope.launch {
            var response = singerApiService.albumPage(id,pageNum,pageSize)
            if (response.isSuccessful){
                if (pageNum == 1) {
                    _initialData.value=response.body()
                } else {
                    _loadMoreData.value=response.body()
                }
            }
        }
    }
}